package cn.zt.service.impl;

import cn.zt.common.Result;
import cn.zt.domain.ProductType;
import cn.zt.mapper.ProductTypeMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.zt.domain.TWealthProduct;
import cn.zt.service.TWealthProductService;
import cn.zt.mapper.TWealthProductMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
* @author 21889
* @description 针对表【t_wealth_product(理财产品表)】的数据库操作Service实现
* @createDate 2024-09-03 19:18:05
*/
@Service
public class TWealthProductServiceImpl extends ServiceImpl<TWealthProductMapper, TWealthProduct>
    implements TWealthProductService{

    @Resource
    private TWealthProductMapper tWealthProductMapper;

    @Resource
    private ProductTypeMapper productTypeMapper;

    @Override
    public Result listWealth(Integer pageNum, Integer pageSize, TWealthProduct wingsProduct) {
        Page<TWealthProduct> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<TWealthProduct> wrapper = Wrappers.<TWealthProduct>lambdaQuery()
                .like(StringUtils.isNotBlank(wingsProduct.getName()), TWealthProduct::getName, wingsProduct.getName())
                .orderByDesc(TWealthProduct::getOrderNum);
        tWealthProductMapper.selectPage(page, wrapper);
        for (TWealthProduct wealthProduct : page.getRecords()) {
            if (wealthProduct.getTypeId() != null){
                ProductType productType = productTypeMapper.selectById(wealthProduct.getTypeId());
                if (productType != null){
                    wealthProduct.setProductType(productType);
                }
            }
        }
        return Result.success(page);
    }
}




